//
//  ViewController.m
//  UI22_数据库
//
//  Created by 才诗琦 on 16/1/7.
//  Copyright © 2016年 www.lanou3g.com. All rights reserved.
//

#import "ViewController.h"
#import "DataBaseManager.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    
    
}
#pragma mark-打开数据库
- (IBAction)openDB:(id)sender {
    
    //创建单例对象
    
    DataBaseManager *dbManager = [DataBaseManager shareInstance];
    //打开数据库
    [dbManager openDB];
}

#pragma mark-关闭数据库
- (IBAction)closeDB:(id)sender {
    
    [[DataBaseManager shareInstance] closeDB];

    
    
}

#pragma mark-创建表
- (IBAction)createTable:(id)sender {
      [[DataBaseManager shareInstance] createTable];
}

#pragma mark-删除表
- (IBAction)dropTable:(id)sender {
}

#pragma mark-添加表
- (IBAction)insertTable:(id)sender {
    
    
    //movie对象
    
    Movie *m = [[Movie alloc] init];
    
    m.movieName = @"唐人街探案";
    
    m.pubDate = @"2016-1-6";
    
    //插入
    
    [[DataBaseManager shareInstance] insertMovie:m];
    
    
}

#pragma mark-删除

- (IBAction)deleteTable:(id)sender {
    
    [[DataBaseManager shareInstance] deleteMovieWithId:2];
    
    
}

#pragma mark-更新
- (IBAction)updateTable:(id)sender {
    
    
    Movie *newM = [[Movie alloc] init];
    
    newM.movieName = @"STAR WARS";
    newM.pubDate = @"随便";
    [[DataBaseManager shareInstance] updateMovie:newM WithId:1];
    
    
}

#pragma mark-查询

- (IBAction)selectTable:(id)sender {
    
    
    NSMutableArray *arr = [[DataBaseManager shareInstance] select];
    
    for (Movie *m in arr) {
        NSLog(@"%@ %@ %ld", m.movieName, m.pubDate, m.movieId);
    }
    
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
